package com.cmict.data.bpm.convert.task;

import com.cmict.data.bpm.controller.admin.task.vo.activity.BpmActivityRespVO;
import oracle.sql.DATE;
import org.apache.commons.lang3.StringUtils;
import org.flowable.engine.history.HistoricActivityInstance;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * BPM 活动 Convert
 *
 * @author awesome
 */
@Mapper
public interface BpmActivityConvert {

    BpmActivityConvert INSTANCE = Mappers.getMapper(BpmActivityConvert.class);

    List<BpmActivityRespVO> convertList(List<HistoricActivityInstance> list);

    public static void main(String[] args) {
//        org.apache.commons.lang3.StringUtils.isBlank(bean.getStartTime()) ? null :
    }
    @Mappings({
            @Mapping(source = "activityId", target = "key"),
            @Mapping(source = "activityType", target = "type"),
            @Mapping(target = "startTime", expression = "java(bean.getStartTime() == null ? null : java.time.LocalDateTime.ofInstant(bean.getStartTime().toInstant(), java.time.ZoneId.systemDefault()))"),
            @Mapping(target = "endTime", expression = "java(bean.getEndTime() == null  ? null : java.time.LocalDateTime.ofInstant(bean.getEndTime().toInstant(), java.time.ZoneId.systemDefault()))"
            )
    })
    BpmActivityRespVO convert(HistoricActivityInstance bean);
}
